42. Common parameters¶
Note
The below information is extensively based in information taken from the PowerShell® Notes for Professionals book. I plan to extend this information based on my day to day usage of the language.
42.1: ErrorAction parameter¶
Possible values are Continue | Ignore | Inquire | SilentlyContinue | Stop | Suspend.
Value of this parameter will determine how the cmdlet will handle non-terminating errors (those generated from Write-Error for example; to learn more about error handling see [ topic not yet created ]).
Default value (if this parameter is omitted) is Continue.
-ErrorAction Continue
This option will produce an error message and will continue with execution.
1 | Write-Error "test" -ErrorAction Continue ; Write-Host "Second command" |
-ErrorAction Ignore
This option will not produce any error message and will continue with execution. Also no errors will be added to $Error automatic variable.
This option was introduced in v3.
1 | Write-Error "test" -ErrorAction Ignore ; Write-Host "Second command" |
-ErrorAction Inquire
This option will produce an error message and will prompt user to choose an action to take.
1 | Write-Error "test" -ErrorAction Inquire ; Write-Host "Second command" |
-ErrorAction SilentlyContinue
This option will not produce an error message and will continue with xecution. All errors will be added to $Error automatic variable.
1 | Write-Error "test" -ErrorAction SilentlyContinue ; Write-Host "Second command" |
-ErrorAction Stop
This option will produce an error message and will not continue with execution.
1 | Write-Error "test" -ErrorAction Stop ; Write-Host "Second command" |
-ErrorAction Suspend
Only available in Powershell Workflows. When used, if the command runs into an error, the workflow is suspended. This allows investigation of such error and gives a possibility to resume the workflow.